<template>
  <el-dialog title="拒绝退款" :visible.sync="dialogVisible" width="500px">
    <div class="title">您确定要拒绝退款吗？</div>
    <el-form :model="form">
      <el-form-item label="原因：" :label-width="formLabelWidth">
        <el-select
          v-model="form.refuse_reason"
          placeholder="请选择"
          @change="changeSelect"
        >
          <el-option label="订单商品已发货" :value="1"></el-option>
          <el-option label="其他原因" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="其他原因：" :label-width="formLabelWidth" v-if="isShowOther">
        <el-input
          type="textarea"
          v-model="form.other"
          autocomplete="off"
          :rows="2"
          placeholder="请输入拒绝退款原因！"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit_refuse">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { adminCheckRefuse, shopCheckRefuse } from "@/api/orderRefund";
export default {
  props: ["refundId", "refundStatus"],
  data() {
    return {
      dialogVisible: false,
      isShowOther: false,
      formLabelWidth: "120px",
      form: {
        refuse_reason: "",
        other: "",
      },
      curReason: ''
    };
  },
  methods: {
    changeSelect(val){
      this.form.other = ''
      if(val == '2'){
        this.isShowOther = true
      } else {
        this.isShowOther = false
      }
    },
    close(){
      this.dialogVisible = false;
      this.form = {
        refuse_reason: "",
        other: "",
      }
      this.isShowOther = false
    },
    submit_refuse() {
      if (!this.form.refuse_reason) {
        this.$message.warning("拒绝原因不能为空");
        return false;
      }
      if (this.form.refuse_reason == 2 && !this.form.other) {
        this.$message.warning("请输入拒绝退款原因！");
        return false;
      }
      if(this.form.refuse_reason == 1){
        this.curReason = '订单商品已发货'
      } else {
        this.curReason = this.form.other
      }
      let obj = {
        refund_id: this.refundId,
        refuse_reason: this.curReason,
      };
      // console.log('res',this.refundStatus ,obj )
      if (this.refundStatus == 3) {
        adminCheckRefuse(obj).then(res => {
          this.close()
          this.$parent.getList();
        });
      } else if (this.refundStatus == 2) {
        shopCheckRefuse(obj).then(res => {
          this.close()
          this.$parent.getList();
        });
      }
    },
  },
  mounted() {},
};
</script>

<style lang="scss" scoped>
.title {
  text-align: center;
  margin: 30px 0 20px;
}
</style>